package com.aaa.controller;


import com.aaa.entity.Back_User;
import com.aaa.entity.Comment;
import com.aaa.entity.Video;
import com.aaa.service.impl.CommentServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Bean
 * @since 2021-09-14
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    CommentServiceImpl commentService;
    @RequestMapping("finAll")
    public PageInfo finAll(Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("state",0);
        List<Comment> list = commentService.list(queryWrapper);
        PageInfo<Comment> rolePageInfo = new PageInfo<Comment>(list);
        return rolePageInfo;
    }
    @RequestMapping("commentRecord")
    public PageInfo commentRecord(Integer pageNum, Integer pageSize,String value){
        System.out.println(value);
        PageHelper.startPage(pageNum,pageSize);
        if(value.equals("0")||value==""||value==null){
            System.out.println("全部");
            QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
            queryWrapper.ne("state",0);
            List<Comment> list = commentService.list(queryWrapper);
            PageInfo<Comment> rolePageInfo = new PageInfo<Comment>(list);
            return rolePageInfo;
        }else{
            System.out.println("我的");
            QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
            queryWrapper.ne("state",0);
            queryWrapper.eq("auditor",value);
            List<Comment> list = commentService.list(queryWrapper);
            PageInfo<Comment> rolePageInfo = new PageInfo<Comment>(list);
            return rolePageInfo;
        }
    }

    @RequestMapping("updateState")
    public boolean updateState(Comment comment){
        System.out.println(comment);
        return commentService.updateById(comment);
    }
}
